package com.njupt.item.controller;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;


/**
 * @Author: XJL
 * @Description:处理网页静态化
 * @Date: Create in 15:46 2018/6/1
 * @Modified By:
 **/
@Controller
public class HtmlGenController {

    @Autowired
    private FreeMarkerConfig freeMarkerConfig;

    @RequestMapping("/genhtml")
    @ResponseBody
    public String getHtml()throws Exception{
        Configuration configuration = freeMarkerConfig.getConfiguration();
        Template template = configuration.getTemplate("hello.ftl");
        Map map = new HashMap();
        map.put("hello",1010101010);
        Writer writer = new FileWriter(new File("D:/freemarker/hello.html"));
        template.process(map,writer);
        writer.close();
        return "ok";
    }
}
